<?php
/**
 * 对象存储服务
 * @文件名称: EmailUtil.php
 * @author: jawei
 * @Email: gaozhiwei@etcp.cn
 * @Date: 2017-06-06
 * @Copyright: 2017 悦畅科技有限公司. All rights reserved.
 * 注意：本内容仅限于悦畅科技有限公司内部传阅，禁止外泄以及用于其他的商业目的
 */
namespace app\components;
use Yii;
class EmailUtil
{
    const SEND_USER = 'gaozhiwei429@sina.com';
    public static function sendBySwift($receiver, $title, $content)
    {
        try{
            return Yii::$app->mailer->compose()
                ->setFrom(self::SEND_USER)
                ->setTo($receiver)
                ->setSubject($title)
//            ->setTextBody('Plain text content')
                ->setHtmlBody($content)
//            ->attach('/data/ditui/rcandidate/ditui-yii/runtime/logs/qiye/'.date('Y-m-d', time()).'.csv')
                ->send();
        }catch (\Exception $e){
            DmpLog::log('email_error, e: ' . $e->getTraceAsString(), false);
            return false;
        }
    }

    public static function sendForCreateUser($email, $account, $password)
    {
        $title = '[企业版系统]线上帐号开通';

        $content = <<<EOT
<div>
<h2>您好!</h2>
<br />
<div>帐号: $account</div>
<br />
<div>密码: $password</div>
<br />
<h3>有问题请联系: <a href="mailto:gaozhiwei429@sina.com">gaozhiwei429@sina.com</a></h3>
</div>
EOT;

        return Yii::$app->mailer->compose()
            ->setFrom(self::SEND_USER)
            ->setTo($email)
            ->setSubject($title)
            ->setHtmlBody($content)
            ->send();
    }
}
